import java.io.*;

// inFile :/Users/yuer/Desktop/a.pdf
public class Main {
    public static void main(String[] args) {

        FileInputStream fis = null;
        FileOutputStream fos = null;

        try {
            File inFile = new File("/Users/yuer/Desktop/a.txt");
            File outFile = new File("b.txt");

            fis = new FileInputStream(inFile);
            fos= new FileOutputStream(outFile);

            int c;

            //单字节拷贝是不可取的，效率很底下，应该采用缓存流，或者是多字节拷贝。
            //单字节拷贝在实际运行业务中，很有可能造成磁盘，磁头的损坏！！！
            while ((c=fis.read())!=-1){
                System.out.print(Integer.toHexString(c));
                fos.write(c);
            }
        } catch (FileNotFoundException e) {
            //throw new RuntimeException(e);
            e.printStackTrace();
        } catch (IOException e) {
            //throw new RuntimeException(e);
            e.printStackTrace();
        } finally {
            if(fis!=null){
                try {
                    fis.close();
                } catch (IOException e) {
                    //throw new RuntimeException(e);
                    e.printStackTrace();
                }
            }

            if(fos!=null){
                try {
                    fos.close();
                } catch (IOException e) {
                    //throw new RuntimeException(e);
                    e.printStackTrace();
                }
            }
            System.out.println("copy over!");
        }
    }
}